﻿// /*
//  * @Author: Dreamy Icecream 
//  * @Date: 2020-12-31 17:04:10 
//  * @Description: 动态模糊
//  * @Last Modified by: Dreamy Icecream 
//  * @Last Modified time: 2020-12-31 17:04:10 
//  */

Shader "Custom/MotionBlur" {

    Properties {
        _MainTex ("Base (RGB)", 2D) = "white" {}
        _BlurAmount ("模糊程度", Float) = 1.0
    }

    SubShader {
       
        CGINCLUDE

        #include "UnityCG.cginc"

        sampler2D _MainTex;
        fixed _BlurAmount;

        struct v2f{
            float4 pos : SV_POSITION;
            half2 uv : TEXCOORD0;
        };

        v2f vert(appdata_img v){
            v2f o;
            o.pos = UnityObjectToClipPos(v.vertex);
            o.uv = v.texcoord;
            return o;
        }

        /** 更新RGB通道 */
        fixed4 fragRGB(v2f i) : SV_TARGET{
            return fixed4(tex2D(_MainTex, i.uv).rgb, _BlurAmount);
        }

        /** 更新A通道 */
        fixed4 fragA(v2f i) : SV_TARGET{
            return tex2D(_MainTex, i.uv);
        }

        ENDCG

        ZTest Always Cull Off ZWrite Off

        Pass{

            Blend SrcAlpha OneMinusSrcAlpha
            ColorMask RGB

            CGPROGRAM

            #pragma vertex vert
            #pragma fragment fragRGB

            ENDCG
        }

        Pass{

            Blend One Zero
            ColorMask A

            CGPROGRAM

            #pragma vertex vert
            #pragma fragment fragA

            ENDCG

        }

    }

    FallBack Off

}
